
package com.weasing.res.web.action;


import org.apache.struts2.ServletActionContext;
import com.weasing.res.domain.WxAdmin;
import com.weasing.res.domain.WxChecklist;
import com.weasing.res.domain.WxEvalresult;
import com.weasing.res.domain.WxUserdetail;
import com.weasing.res.domain.WxUserlist;
import com.weasing.res.service.IWxAdminService;
import com.weasing.res.service.IWxChecklistService;
import com.weasing.res.service.IWxEvalresultService;
import com.weasing.res.service.IWxUserdetailService;
import com.weasing.res.service.IWxUserlistService;
import com.weasing.res.utils.RESUtils;
import com.weasing.res.utils.StringUtil;
import com.weasing.res.vo.WxChecklistVO;
import com.weasing.res.web.action.base.BaseAction;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import net.sf.json.JSONObject;
//审核审批表
@Controller
@Scope("prototype")
public class WxChecklistAction extends BaseAction<WxChecklist> {
    @Autowired
    private IWxChecklistService wxChecklistService;
    @Autowired
    private IWxAdminService wxAdminService;
    @Autowired
    private IWxUserdetailService wxUserdetailService;
    @Autowired
    private IWxEvalresultService wxEvalresultService;
    @Autowired
    private IWxUserlistService wxUserlistService;
    
    private List<WxChecklist> wxChecklist;
    private List<WxChecklistVO> wxChecklistvo;
    private List<Map> datalist;
    private WxChecklist wxaddcheck;
    public String jsonlist(){
        String curpage = RESUtils.getRequest().getParameter("currentPage");
        if (StringUtil.isNotNulls(curpage)) {
            int currentPage = Integer.valueOf(curpage);
            pageBean.setCurrentPage(currentPage);
        }
        int toadminid = Integer.valueOf(RESUtils.getRequest().getParameter("toadminid"));
        int status = Integer.valueOf(RESUtils.getRequest().getParameter("status"));
        wxChecklistService.findWxChecklistByCondition(toadminid, status, pageBean);
        int totalpage=pageBean.getTotalPage();
        
        datalist=new ArrayList<Map>();
        List<WxChecklist> rows=pageBean.getRows();
        
        for(int i=0;i<rows.size();i++){//组合字符串
            Map<String,Object> itemmap = new HashMap<String, Object>();
            String id=rows.get(i).getId().toString();
            itemmap.put("id",id);
            String createtime=rows.get(i).getCreatetime().toString();
            itemmap.put("createtime",createtime);
            
            WxAdmin wxadmin=wxAdminService.findById(rows.get(i).getFadminid());
            String sendname=wxadmin.getTruename();
            itemmap.put("sendname",sendname);
            
            WxUserlist wxuserlist=wxUserlistService.findById(rows.get(i).getUserid());
            WxUserdetail wxuserdetail=wxUserdetailService.findById(rows.get(i).getUdetailid());
            String checkname = wxuserlist.getTruename()+wxuserdetail.getChargename()+"羁押必要性评估";
            itemmap.put("checkname",checkname);
            itemmap.put("udetailid",rows.get(i).getUdetailid());
            WxEvalresult wxevalresult=wxEvalresultService.findById(rows.get(i).getEresultid());
            String erestr="";
            if(wxevalresult.getTotalscore()>-6){
                erestr="需要羁押";
            }else{
                erestr="无羁押必要";
            }
            itemmap.put("eresultid",rows.get(i).getEresultid());
            itemmap.put("erestr",erestr);
            datalist.add(itemmap);
            }
        
            Map<String,Object> jsonmap = new HashMap<String, Object>();
            jsonmap.put("success", "success");
            jsonmap.put("totalpage",totalpage);
            jsonmap.put("currentPage",curpage);
            jsonmap.put("data",datalist);
          
            JSONObject json = JSONObject.fromObject(jsonmap);
            ServletActionContext.getResponse().setContentType("text/html;charset=UTF-8");
            RESUtils.print(json.toString());
            return null;
    }
    
    public String addchecklist(){
			wxaddcheck=new WxChecklist();
            int fadminid = Integer.valueOf(RESUtils.getRequest().getParameter("fadminid"));
            int toadminid = Integer.valueOf(RESUtils.getRequest().getParameter("toadminid"));
            int userid = Integer.valueOf(RESUtils.getRequest().getParameter("userid"));
            int udetailid = Integer.valueOf(RESUtils.getRequest().getParameter("udetailid"));
            int eresultid = Integer.valueOf(RESUtils.getRequest().getParameter("eresultid"));
            wxaddcheck.setFadminid(fadminid);
			wxaddcheck.setToadminid(toadminid);
			wxaddcheck.setUserid(userid);
			wxaddcheck.setUdetailid(udetailid);
			wxaddcheck.setEresultid(eresultid);
            wxaddcheck.setStatus(-1);
            wxaddcheck.setCreatetime(new Timestamp(System.currentTimeMillis()));
            wxChecklistService.save(wxaddcheck);
            Map<String,Object> jsonmap = new HashMap<String, Object>();
            jsonmap.put("success", "success");
            JSONObject json = JSONObject.fromObject(jsonmap);
            ServletActionContext.getResponse().setContentType("text/html;charset=UTF-8");
            RESUtils.print(json.toString());
    
        return null;
    } 
    
    public String changestatus(){
        String ids = RESUtils.getRequest().getParameter("id");
        if(ids!=null){
            int id = Integer.valueOf(ids);
            int status = Integer.valueOf(RESUtils.getRequest().getParameter("status"));
            wxChecklistService.upStatusByID(id, status);
            Map<String,Object> jsonmap = new HashMap<String, Object>();
            jsonmap.put("success", "success");
            JSONObject json = JSONObject.fromObject(jsonmap);
            ServletActionContext.getResponse().setContentType("text/html;charset=UTF-8");
            RESUtils.print(json.toString());
        }
        return null;
    }
    
}
